package br.unirio.webdisco.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import br.unirio.webdisco.dao.impl.DNAPostgresDAO;
import br.unirio.webdisco.dao.impl.DoencaPostgresDAO;
import br.unirio.webdisco.dao.impl.PesquisaPostgresDAO;
import br.unirio.webdisco.entity.DNA;
import br.unirio.webdisco.entity.Doenca;
import br.unirio.webdisco.entity.Pesquisa;

import com.opensymphony.xwork2.ActionSupport;
 
public class DownloadAction extends ActionSupport{
 
	private InputStream fileInputStream;
	private Integer currentIdUsuarioDNA;
	private Integer currentIdUsuarioDoencas;
	
	public void setIdUsuarioDNA(Integer currentIdUsuarioDNA) {
		this.currentIdUsuarioDNA = currentIdUsuarioDNA;
	}
	
	public void setIdUsuarioDoencas(Integer currentIdUsuarioDoencas) {
		this.currentIdUsuarioDoencas = currentIdUsuarioDoencas;
	}
	
	public InputStream getFileInputStream() {
		return fileInputStream;
	}
 
	public String execute() throws Exception {
		
		DNAPostgresDAO DNAConsulta = new DNAPostgresDAO();
	    
		DNA dna = new DNA();
		dna = DNAConsulta.consultarPorUsuario(currentIdUsuarioDNA);
		
		if(dna != null)
	    {
			fileInputStream = new FileInputStream(new File("C:\\uploads\\" + dna.getSequencia()));
	    	return SUCCESS;
	    }else
	    	return INPUT;
	}

	
	public String doencas() throws Exception {
		
		PesquisaPostgresDAO PesquisaConsulta = new PesquisaPostgresDAO();
		
		boolean temArquivo;
		temArquivo = PesquisaConsulta.relatorioDoencas(currentIdUsuarioDoencas);
		
		if(temArquivo)
		{
		fileInputStream = new FileInputStream(new File("C:\\uploads\\ProprencaoDoencas.txt"));
	    return SUCCESS;
		}else
			return INPUT;
	    
	}
}